﻿using LogDashboard;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

namespace Luka;

/// <summary>
/// 日志面板
/// </summary>
[NotScanned]
public static class LogDashboardSetup
{
    public static IServiceCollection AddLogPage(this IServiceCollection services)
    {
        var setting = InternalApp.GetSection<LogOptions>("Logs");
        //自定义可视化日志面板路径
        if (setting?.FileLog?.IsEnable == true)
        {
            services.AddLogDashboard(options =>
            {
                options.PathMatch = setting.FileLog?.PagePath ?? "/Log";
            });
        }

        return services;
    }

    /// <summary>
    /// 使用日志可视化页面
    /// </summary>
    public static IApplicationBuilder UseLogPage(this IApplicationBuilder app)
    {
        var setting = InternalApp.GetSection<LogOptions>("Logs");
        if (setting?.FileLog?.IsEnable == true)
        {
            app.UseDeveloperExceptionPage();
            app.UseLogDashboard(setting.FileLog?.PagePath ?? "/Log");
        }
        return app;
    }
}